<?php
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/common/css_form/catcha_slider.css');

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/assets/javaScript/js_catcha_slider/jquery.ui.touch.js',CClientScript::POS_BEGIN);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/assets/javaScript/js_catcha_slider/QapTcha.jquery.js',CClientScript::POS_BEGIN);

echo $this->renderPartial("leftnav");
?>

<script type="text/javascript">
function form_onsubmit(param)
{
    if ( document.forms[param].txt_name.value == "" )
    {
        $('#lbl_name_validation').fadeIn("slow", "linear");
        document.forms[param].txt_name.focus();
        return false;
    }

    if ( document.forms[param].ta_address.value == "" )
    {
        $('#lbl_address_validation').fadeIn("slow", "linear");
        document.forms[param].ta_address.focus();
        return false;
    }

    return true;
}

function echeck(d)
{
    return /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(d);
}

jQuery(document).ready(function() {

    $( "#dialog_excute" ).dialog({
        autoOpen      : false,
        closeOnEscape : false,
        width         : 220,
        height        : 140,
        modal         : true,
        resizable     : false,
        show          : "explode",
        hide          : "explode",
        open          : function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
    });

    $( "#dialog_notice" ).dialog({
        autoOpen      : false,
        closeOnEscape : false,
        width         : 500,
        height        : 140,
        modal         : true,
        show          : "explode",
        hide          : "explode",
        open          : function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
        buttons       : {
            Ok: function() {
                $( this ).dialog( "close" );
                load_page("");
            }
        }
    });

    $("#QapTcha").QapTcha({disabledSubmit:true,autoRevert:true});

    //attach a submit handler to the form
    $("#frm_checkout").submit(function(event) {
        //stop form from submitting normally
        event.preventDefault();

        var bool_submit = form_onsubmit("frm_checkout");
        if (bool_submit == true)
        {
            $( "#dialog_excute" ).dialog( "open" );

            // get some values from elements on the page: 
            var $form = $(this),
            url       = $form.attr("action");

            $.post(
                url,
                {
                   hidd_payMethod   : 1,
                   txt_name         : $form.find( 'input[name="txt_name"]' ).val(),
                   txt_phone        : $("#txt_phone").val(),
                   txt_deliveryDate : $("#txt_deliveryDate").val(),
                   ta_address       : $("#ta_address").val(),
                   ta_information   : $("#ta_information").val(),
                },
                function( response )
                {
                    var arr_result = $.parseJSON(response);

                    if(arr_result.errorMsg != null)
                    {
                        $( "#dialog_notice" ).children().html(arr_result.errorMsg);
                        $( "#dialog_excute" ).dialog( "close" );
                        $( "#dialog_notice" ).dialog( "open" );
                        return;
                    }

                    if ( arr_result.result == true )
                    {
                       $( "#dialog_notice" ).children().html(arr_result.resultMsg);
                       $( "#dialog_excute" ).dialog( "close" );
                       $( "#dialog_notice" ).dialog( "open" );
                    }//End if
                }
            );
        }//End if
    });
});
    
</script>

<!-- ================================== 712 Area - Right Side =========================================================== -->
<div class="grid_712">
    <div class="box">
        <h1>Thanh Toán</h1>

        <form
            id     = "frm_checkout"
            name   = "frm_checkout"
            action = "<?=Yii::app()->createAbsoluteUrl("cart/order");?>"
            method = "post"
            class  = "form_input"
        >
            <fieldset class="border_radius_all">
                <div class="form_input_row">
                    <label class="label_title">Họ và Tên:*</label>
                    <input
                        id       = "txt_name"
                        name     = "txt_name"
                        title    = "Họ và tên của tên bạn"
                        type     = "text"
                        value    = "<?php if($o_account instanceof Account) echo $o_account->name;?>"
                        class    = "form_textbox textbox_css3"
                        tabindex = "1"
                        onblur   = "validation_empty(this,$(this).next())"
                    />
                    <label
                        id    = "lbl_name_validation" 
                        class = "lable_validation"
                    >Bạn chưa nhập họ và tên.</label>
                </div>

                <div class="form_input_row">
                    <label class="label_title">Số Điện Thoại:*</label>
                    <input
                        id       = "txt_phone"
                        name     = "txt_phone"
                        title    = "Số Điện Thoại bạn"
                        type     = "text"
                        value    = "<?php if($o_account instanceof Account) echo $o_account->phone;?>"
                        class    = "form_textbox textbox_css3"
                        tabindex = "2"
                        onblur   = "validation_empty(this,$(this).next())"
                    />
                    <label
                        id        = "lbl_phone_validation" 
                        class    = "lable_validation"
                    >Bạn chưa nhập số điện thoại.</label>
                </div>
                
                <div class="form_input_row">
                    <label class="label_title">Địa Chỉ Giao*:</label>
                    <textarea 
                        id       = "ta_address"
                        name     = "ta_address"
                        rows     = "6"
                        cols     = ""
                        class    = "form_textarea textarea_css3"
                        tabindex = "3"
                        onblur   = "validation_empty(this,$(this).next())"
                    ><?php if($o_account instanceof Account) echo $o_account->address?></textarea>
                    <label
                        id    = "lbl_address_validation" 
                        class = "lable_validation"
                    >Bạn chưa nhập địa chỉ.</label>
                </div>

                <div class="form_input_row">
                    <label class="label_title">Ngày Giao Hàng*:</label>
                    <input
                        id       = "txt_deliveryDate"
                        name     = "txt_deliveryDate"
                        title    = "Ngày Giao Hàng"
                        type     = "text"
                        value    = ""
                        class    = "form_textbox textbox_css3"
                        tabindex = "4"
                    />
                </div>

                <div class="form_input_row">
                    <label class="label_title">Ghi Chú:</label>
                    <textarea 
                        id       = "ta_information"
                        name     = "ta_information"
                        rows     = "6"
                        cols     = ""
                        class    = "form_textarea textarea_css3"
                        tabindex = "5"
                    ></textarea>
                </div>

                <div class="form_input_row">
                    <label class="label_title">Mã Xác Nhận:*</label>
                    <div class="input_items_horizon" style="padding-top: 0px;">
                        <div id="QapTcha"></div>
                    </div>
                </div>

                <div class="form_input_row" style="border: none;">
                    <div class="input_items_horizon">
                        <input
                            title    = "gửi yêu cầu"
                            name     = "btn_checkout"
                            id       = "btn_checkout"
                            type     = "submit"
                            value    = "Đặt Hàng"
                            class    = "button_css3 input_button"
                            tabindex = "6"
                        />
                    </div>
                </div>

            </fieldset>
        </form>
    </div>
</div>

<div
    id    = "dialog_excute"
    title = "Chương trình đang thực thi"
    class = "dialog_message"
>
    <p class="center">
        <img 
            alt    = "Loading...."
            src    = "<?=Yii::app()->baseUrl;?>/images/image_default/loading_circle.gif"
            width  = "92px"
            height = "92px"
        />
    </p>
</div>

<div
    id    = "dialog_notice"
    title = "Thông Báo"
    class = "dialog_message"
>
    <p class="center">
    </p>
</div>
<!-- ================================ End 712 Area - Right Side ========================================================= -->